<template>
  <div>
    <el-form ref="formMatter" :model="formMatter" :inline="true">
      <el-form-item label="顾客名称" prop="customerName">
        <el-select v-model="formMatter.customerName" filterable placeholder="请输入顾客名称" allow-create default-first-option clearable>
          <el-option
            v-for="item in customerList"
            :key="item.id"
            :label="item.customerName"
            :value="item.customerName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="当前状态" prop="statusId">
        <el-select v-model="formMatter.statusId" filterable size="mini" clearable>
          <el-option v-for="item in statuses" :key="item" :value="item" :label="item" />
        </el-select>
      </el-form-item>
      <el-form-item label="提交日期" prop="submitTime">
        <el-date-picker v-model="formMatter.submitTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="编号" prop="code">
        <el-input v-model="formMatter.code" size="mini" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item>
      <el-button type="primary" size="mini" @click="gethasBeenSent()">查询</el-button>
      <el-button type="success" size="mini"
      @click="() => { $refs.formMatter.resetFields(); handleCurrentChange(1) }">重置</el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-card style="height: 100%">
        <div slot="header">已发起评审</div>
        <hmi-table :table-data="tableData" :table-head="true" :is-pagination-show="true"
          :table-height="'calc(100vh - 230px)'" :total="total" :current-page="formMatter.current"
          :page-size="formMatter.page" index-type="index" @handle-size-change="handleSizeChange"
          @handle-current-change="handleCurrentChange">
          <template slot="TableBody">
            <el-table-column label="编号" align="center" prop="code"></el-table-column>
            <el-table-column label="当前状态" align="center" prop="statusName" width="120">
              <template slot-scope="scope">
                {{ scope.row.statusName }}
              </template>
            </el-table-column>
            <el-table-column label="顾客名称" align="center" prop="customerName" width="200"></el-table-column>
            <el-table-column label="顾客联系方式" align="center" width="130" prop="customerPhone"></el-table-column>
            <el-table-column label="钢类" align="center" prop="steelTypeName"></el-table-column>
            <el-table-column label="钢种" align="center" prop="steelGradeName" show-overflow-tooltip></el-table-column>
            <el-table-column label="标准" align="center" prop="standardName" show-overflow-tooltip></el-table-column>
            <el-table-column label="规格" align="center" prop="specification"></el-table-column>
            <el-table-column label="数量" align="center" prop="steelNumber">
              <template slot-scope="scope">
                {{ scope.row.steelNumber }}{{ scope.row.steelNumberUnit }}
              </template>
            </el-table-column>
            <el-table-column label="交货状态" align="center" prop="deliveryStatus"></el-table-column>
            <el-table-column label="加工用途" align="center" prop="processingPurpose"></el-table-column>
            <el-table-column label="提交时间" align="center" prop="submitTime" width="180">
              <template slot-scope="scope">
                <span>{{ formatterTime(scope.row.submitTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="text" size="mini" @click="hanldeDetail(scope.row)">查看</el-button>
              </template>
            </el-table-column>
          </template>
        </hmi-table>
      </el-card>
    </div>
  </div>
</template>

<script>
import HmiTable from "@/components/HmiTable.vue";
import { timeChange } from "@/lib/FormatTime";
import { GET_SALE_SENTREVIEW, GET_CUSTOMERNAMELIST } from "@/lib/Api.js";
import { post } from "@/lib/Util.js";
export default {
  components: {
    HmiTable
  },
  data() {
    return {
      total: 0,
      formMatter: {
        code: "",
        current: 1,
        page: 5,
        customerName: "",
        statusId: "",
        submitTime: ""
      },
      statuses: [],
      tableData: [],
      customerList: []
    };
  },
  mounted() {
    this.gethasBeenSent(); // 组件挂载后立即执行
    this.getCustomerNames(); // 获取顾客
  },
  methods: {
    /**
     * 格式化日期方法
     */
    formatterTime(time) {
      if (time !== "" && time !== undefined) {
        return timeChange(time);
      } else {
        return "";
      }
    },
    //获取已发送评审
    gethasBeenSent() {
      post(GET_SALE_SENTREVIEW, this.formMatter).then(resp => {
        const { total, rows } = resp;
        this.total = total;
        this.tableData = rows;
      });
    },
    hanldeDetail(row) {
      if (row.code !== null) {
        this.$router.push({
          name: "sale-orderDetails", // "standard-approvedOrder-infoCompliance",
          params: {
            id: row.id
          }
        });
      } else {
        this.$router.push({
          path: "/sale/orderDetails2",
          query: {
            id: row.id
          }
        });
      }
    },

    //当前页改变
    handleCurrentChange(current) {
      this.formMatter.current = current;
      this.gethasBeenSent();
    },
    //每页记录数改变
    handleSizeChange(page) {
      this.formMatter.page = page;
      this.handleCurrentChange(1);
    },
    // 获取顾客
    getCustomerNames() {
      post(GET_CUSTOMERNAMELIST, { customerName: "" }).then(resp => {
        this.customerList = resp.data;
      });
    }
  }
};
</script>

<style scoped>
</style>
